﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.Restaurant;

namespace FwProject.Manager
{
    public class RestaurantInfoManager: IDomainService
    {
        private readonly IRepository<RestaurantInfo, Guid> _restaurantRepository;
        public RestaurantInfoManager(IRepository<RestaurantInfo, Guid> restaurantRepository)
        {
            _restaurantRepository = restaurantRepository;

        }
        /// <summary>
        /// 添加一个餐厅
        /// </summary>
        /// <param name="restaurant"></param>
        /// <returns></returns>
        public async Task<Guid> CreateRestaurant(RestaurantInfo restaurant)
        {

            var model = _restaurantRepository.GetAll().Where(o => o.RestaurantName == restaurant.RestaurantName).FirstOrDefault();
            if (model != null)
                throw new UserFriendlyException("当前餐厅已存在");

            return await _restaurantRepository.InsertAndGetIdAsync(restaurant);
        }
        /// <summary>
        ///修改一个配送汽车
        /// </summary>
        /// <param name="restaurant"></param>
        /// <returns></returns>
        public async Task UpdateRestaurant(RestaurantInfo restaurant)
        {

            await _restaurantRepository.UpdateAsync(restaurant);
        }
        /// <summary>
        ///  delete 一个配送汽车
        /// </summary>
        /// <param name="restaurant"></param>
        /// <returns></returns>
        public async Task DeleteRestaurant(RestaurantInfo restaurant)
        {

            await _restaurantRepository.DeleteAsync(restaurant);
        }
    }
}
